/**
 * Candidate number: 35834
 */
package tv.starfu.sequencer.components;

import com.artemis.Component;
import java.util.ArrayList;
import java.util.TreeMap;
import tv.starfu.sequencer.components.TimeVector;
import tv.starfu.sequencer.components.old.Event;
import tv.starfu.sequencer.model.Track;

public class SequenceComponent extends Component {
    private TreeMap<TimeVector, ArrayList<Event>> eventMap;
    
    private String style;
    private int sequenceID;
    private int numChannels;
    private int length;

    private boolean isPlaying;

    public SequenceComponent(TreeMap<TimeVector, ArrayList<Event>> eventMap, String style, int sequenceID, int numChannels, int length) {
        this.eventMap = eventMap;
        this.style = style;
        this.sequenceID = sequenceID;
        this.numChannels = numChannels;
        this.length = length;
    }

    
    
    // TO-DO
    // Implement sort SequenceComponent
    public void sort() {
        
    }
    
    /**
     * Add Event to SequenceComponent at given TimeVector
     * @param tv
     * @param event 
     */
    public void addEvent(TimeVector tv, Event event) {
        if(!eventMap.containsKey(tv)) {
            ArrayList<Event> events = new ArrayList<Event>();
            events.add(event);
            eventMap.put(tv, events); 
        }
        else { 
            eventMap.get(tv).add(event);
        }
    }
    
    /**
     * Add EventS to SequenceComponent at given TimeVector
     * @param tv
     * @param event 
     */
    public void addEvents(TimeVector tv, ArrayList<Event> events) {
        if(!eventMap.containsKey(tv)) {
            eventMap.put(tv, events); 
        }
        else { 
            eventMap.get(tv).addAll(events);
        }
    }
    
    // TO-DO
    // Comparator
    
    
    /**
     * Get Event(s) at selected TimeVector
     * @param tv
     * @return Events or Null
     */
    public ArrayList<Event> getEvents(TimeVector tv) {
        if(eventMap.containsKey(tv)) {
            ArrayList<Event> e = eventMap.get(tv);
            return e;
        }
        return null;
    }
    
    public void play(TimeVector currentTV, Track track) {
        ArrayList<Event> events = eventMap.get(currentTV);
    }
    
    
    
    public boolean isIsPlaying() {
        return isPlaying;
    }

    public void setIsPlaying(boolean isPlaying) {
        this.isPlaying = isPlaying;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public String getStyle() {
        return style;
    }

    public void setStyle(String style) {
        this.style = style;
    }

}


/* Entity Ideas : 
 *         SequenceComponent (SequenceComponent + Channel)
 *         FXSequence (FXPattern + EffectID)
 * 
 */